package com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.entity.req.*;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationWelcome.service.RxRegistrationWelcomeReductionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.Future;

/**
 * <p>
 * 招生管理学生减免申请表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-05-16
 */
@RestController
@RequestMapping("/rxRegistrationWelcome/reduction")
@SecretBody
public class RxRegistrationWelcomeReductionController {

    @Resource
    private RxRegistrationWelcomeReductionService rxRegistrationWelcomeReductionService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("缓交申请")
    @PostMapping("/add")
    @RequestPass
    public ResponseResult addRegistrationWelcomeReduction(@RequestBody RxRegistrationWelcomeReductionReq addReq) {
        return rxRegistrationWelcomeReductionService.addRegistrationWelcomeReduction(addReq);
    }

    @ApiOperation("查看申请列表")
    @GetMapping("/list")
    public ResponseResult getRegistrationWelcomeReductionList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                              @RequestParam(value = "stuName", required = false) String stuName,
                                                              @RequestParam(value = "idCard", required = false) String idCard,
                                                              @RequestParam(value = "allowStatus", required = false) Integer allowStatus
    ) {
        return rxRegistrationWelcomeReductionService.getRegistrationWelcomeReductionList(pageNum, pageSize, stuName, idCard, allowStatus);
    }

    @ApiOperation("查看申请详情")
    @GetMapping("/detail")
    @RequestPass
    public ResponseResult getRegistrationWelcomeReductionDetail(@RequestParam(value = "applyId") String applyId) {
        return rxRegistrationWelcomeReductionService.getRegistrationWelcomeReductionDetail(applyId);
    }

//    @ApiOperation("学生应该缴费清单")
//    @PostMapping("/paymentCategory/batch/export")
//    public ResponseResult exportStuShouldPaymentCategory(@RequestBody RxRegistrationAdvanceStudentInfoReduceExportReq exportReq,
//                                        HttpServletResponse response) {
//        ResponseResult responseResult;
//        try {
//            Future<ResponseResult> future = rxRegistrationWelcomeReductionService.exportStuShouldPaymentCategory(exportReq, response);
//            while (true) {
//                if (future.isDone()) {
//                    break;
//                }
//            }
//            responseResult = future.get();
//        } catch (Exception e) {
//            e.printStackTrace();
//            responseResult = CommonResult.failed(CommonCodeEnum.FAIL);
//        }
//        return responseResult;
//    }

    @ApiOperation("审批")
    @PostMapping("/allow")
    public ResponseResult allowRegistrationWelcomeReduction(@RequestBody RxRegistrationWelcomeDelayAllowReq allowReq, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return rxRegistrationWelcomeReductionService.allowRegistrationWelcomeReduction(allowReq, user_id);

    }
    @ApiOperation("审批")//未用
    @PostMapping("/allow1")
    public ResponseResult allowRegistrationWelcomeReduction1(@RequestBody RxRegistrationWelcomeDelayAllowReq allowReq, HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try{
            Future<ResponseResult> future = rxRegistrationWelcomeReductionService.allowRegistrationWelcomeReduction1(allowReq,user_id);
            while (true){
                if (future.isDone()){
                    commonCodeEnum = future.get();
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @ApiOperation("查看自己申请")
    @GetMapping("/getMyApply")
    @RequestPass
    public ResponseResult getMyApply(@RequestParam(value = "stuId") String stuId) {
        return rxRegistrationWelcomeReductionService.getMyApply(stuId);
    }

    @ApiOperation("撤销缓交申请")
    @PostMapping("/cancel")
    @RequestPass
    public ResponseResult cancelRegistrationWelcomeReduction(@RequestBody RxRegistrationWelcomeReductionReq cancelReq) {
        return rxRegistrationWelcomeReductionService.cancelRegistrationWelcomeReduction(cancelReq);
    }

}

